<?php


abstract class BaseContratacionContrato extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $id;

	
	protected $fecha_creacion;

	
	protected $fecha_inicial;

	
	protected $fecha_final;

	
	protected $activo;

	
	protected $modelo_id;

	
	protected $tercero_id;

	
	protected $usuario_id;

	
	protected $aContratacionModelo;

	
	protected $aKernelTercero;

	
	protected $aKernelUsuario;

	
	protected $collContratacionAfiliacions;

	
	private $lastContratacionAfiliacionCriteria = null;

	
	protected $collContratacionContratoAVariables;

	
	private $lastContratacionContratoAVariableCriteria = null;

	
	protected $collContratacionOtroSis;

	
	private $lastContratacionOtroSiCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getFechaCreacion($format = 'Y-m-d H:i:s')
	{

		if ($this->fecha_creacion === null) {
			return null;
		}



		try {
			$dt = new DateTime($this->fecha_creacion);
		} catch (Exception $x) {
			throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->fecha_creacion, true), $x);
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getFechaInicial($format = '%x')
	{

		if ($this->fecha_inicial === null) {
			return null;
		}



		try {
			$dt = new DateTime($this->fecha_inicial);
		} catch (Exception $x) {
			throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->fecha_inicial, true), $x);
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getFechaFinal($format = '%x')
	{

		if ($this->fecha_final === null) {
			return null;
		}



		try {
			$dt = new DateTime($this->fecha_final);
		} catch (Exception $x) {
			throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->fecha_final, true), $x);
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function getActivo()
	{
		return $this->activo;
	}

	
	public function getModeloId()
	{
		return $this->modelo_id;
	}

	
	public function getTerceroId()
	{
		return $this->tercero_id;
	}

	
	public function getUsuarioId()
	{
		return $this->usuario_id;
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ContratacionContratoPeer::ID;
		}

		return $this;
	} 
	
	public function setFechaCreacion($v)
	{
		if ($v === null) {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->fecha_creacion !== null || $dt !== null ) {
			
			$currNorm = ($this->fecha_creacion !== null && $tmpDt = new DateTime($this->fecha_creacion)) ? $tmpDt->format('Y-m-d\\TH:i:sO') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d\\TH:i:sO') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->fecha_creacion = ($dt ? $dt->format('Y-m-d\\TH:i:sO') : null);
				$this->modifiedColumns[] = ContratacionContratoPeer::FECHA_CREACION;
			}
		} 
		return $this;
	} 
	
	public function setFechaInicial($v)
	{
		if ($v === null) {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->fecha_inicial !== null || $dt !== null ) {
			
			$currNorm = ($this->fecha_inicial !== null && $tmpDt = new DateTime($this->fecha_inicial)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->fecha_inicial = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = ContratacionContratoPeer::FECHA_INICIAL;
			}
		} 
		return $this;
	} 
	
	public function setFechaFinal($v)
	{
		if ($v === null) {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->fecha_final !== null || $dt !== null ) {
			
			$currNorm = ($this->fecha_final !== null && $tmpDt = new DateTime($this->fecha_final)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->fecha_final = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = ContratacionContratoPeer::FECHA_FINAL;
			}
		} 
		return $this;
	} 
	
	public function setActivo($v)
	{
		if ($v !== null) {
			$v = (boolean) $v;
		}

		if ($this->activo !== $v) {
			$this->activo = $v;
			$this->modifiedColumns[] = ContratacionContratoPeer::ACTIVO;
		}

		return $this;
	} 
	
	public function setModeloId($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->modelo_id !== $v) {
			$this->modelo_id = $v;
			$this->modifiedColumns[] = ContratacionContratoPeer::MODELO_ID;
		}

		if ($this->aContratacionModelo !== null && $this->aContratacionModelo->getId() !== $v) {
			$this->aContratacionModelo = null;
		}

		return $this;
	} 
	
	public function setTerceroId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->tercero_id !== $v) {
			$this->tercero_id = $v;
			$this->modifiedColumns[] = ContratacionContratoPeer::TERCERO_ID;
		}

		if ($this->aKernelTercero !== null && $this->aKernelTercero->getId() !== $v) {
			$this->aKernelTercero = null;
		}

		return $this;
	} 
	
	public function setUsuarioId($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->usuario_id !== $v) {
			$this->usuario_id = $v;
			$this->modifiedColumns[] = ContratacionContratoPeer::USUARIO_ID;
		}

		if ($this->aKernelUsuario !== null && $this->aKernelUsuario->getId() !== $v) {
			$this->aKernelUsuario = null;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array())) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (string) $row[$startcol + 0] : null;
			$this->fecha_creacion = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->fecha_inicial = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->fecha_final = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->activo = ($row[$startcol + 4] !== null) ? (boolean) $row[$startcol + 4] : null;
			$this->modelo_id = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->tercero_id = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
			$this->usuario_id = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating ContratacionContrato object", $e);
		}
	}

	
	public function ensureConsistency()
	{

		if ($this->aContratacionModelo !== null && $this->modelo_id !== $this->aContratacionModelo->getId()) {
			$this->aContratacionModelo = null;
		}
	
		if ($this->aKernelTercero !== null && $this->tercero_id !== $this->aKernelTercero->getId()) {
			$this->aKernelTercero = null;
		}
	
		if ($this->aKernelUsuario !== null && $this->usuario_id !== $this->aKernelUsuario->getId()) {
			$this->aKernelUsuario = null;
		}
	
	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ContratacionContratoPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = ContratacionContratoPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->aContratacionModelo = null;
			$this->aKernelTercero = null;
			$this->aKernelUsuario = null;
			$this->collContratacionAfiliacions = null;
			$this->lastContratacionAfiliacionCriteria = null;

			$this->collContratacionContratoAVariables = null;
			$this->lastContratacionContratoAVariableCriteria = null;

			$this->collContratacionOtroSis = null;
			$this->lastContratacionOtroSiCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ContratacionContratoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		try {
			$con->beginTransaction();
			ContratacionContratoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ContratacionContratoPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		try {
		    if($this->validate())
		    {
    			$con->beginTransaction();
    			$affectedRows = $this->doSave($con);
    			$con->commit();
    			ContratacionContratoPeer::addInstanceToPool($this);
    			return true;
			}else
			{
			     
                 return false;
            }
		} catch (PropelException $e) {
			$con->rollback();
			
			
			ErrorLog::reportarError('errors', 'error',  $e->getMessage() );
			return false;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

												
			if ($this->aContratacionModelo !== null) {
				if ($this->aContratacionModelo->isModified() || $this->aContratacionModelo->isNew()) {
					$affectedRows += $this->aContratacionModelo->save($con);
				}
				$this->setContratacionModelo($this->aContratacionModelo);
			}

			if ($this->aKernelTercero !== null) {
				if ($this->aKernelTercero->isModified() || $this->aKernelTercero->isNew()) {
					$affectedRows += $this->aKernelTercero->save($con);
				}
				$this->setKernelTercero($this->aKernelTercero);
			}

			if ($this->aKernelUsuario !== null) {
				if ($this->aKernelUsuario->isModified() || $this->aKernelUsuario->isNew()) {
					$affectedRows += $this->aKernelUsuario->save($con);
				}
				$this->setKernelUsuario($this->aKernelUsuario);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ContratacionContratoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += ContratacionContratoPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collContratacionAfiliacions !== null) {
				foreach ($this->collContratacionAfiliacions as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collContratacionContratoAVariables !== null) {
				foreach ($this->collContratacionContratoAVariables as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collContratacionOtroSis !== null) {
				foreach ($this->collContratacionOtroSis as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aContratacionModelo !== null) {
				if (!$this->aContratacionModelo->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aContratacionModelo->getValidationFailures());
				}
			}

			if ($this->aKernelTercero !== null) {
				if (!$this->aKernelTercero->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aKernelTercero->getValidationFailures());
				}
			}

			if ($this->aKernelUsuario !== null) {
				if (!$this->aKernelUsuario->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aKernelUsuario->getValidationFailures());
				}
			}


			if (($retval = ContratacionContratoPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collContratacionAfiliacions !== null) {
					foreach ($this->collContratacionAfiliacions as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collContratacionContratoAVariables !== null) {
					foreach ($this->collContratacionContratoAVariables as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collContratacionOtroSis !== null) {
					foreach ($this->collContratacionOtroSis as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ContratacionContratoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getFechaCreacion();
				break;
			case 2:
				return $this->getFechaInicial();
				break;
			case 3:
				return $this->getFechaFinal();
				break;
			case 4:
				return $this->getActivo();
				break;
			case 5:
				return $this->getModeloId();
				break;
			case 6:
				return $this->getTerceroId();
				break;
			case 7:
				return $this->getUsuarioId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = ContratacionContratoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getFechaCreacion(),
			$keys[2] => $this->getFechaInicial(),
			$keys[3] => $this->getFechaFinal(),
			$keys[4] => $this->getActivo(),
			$keys[5] => $this->getModeloId(),
			$keys[6] => $this->getTerceroId(),
			$keys[7] => $this->getUsuarioId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ContratacionContratoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setFechaCreacion($value);
				break;
			case 2:
				$this->setFechaInicial($value);
				break;
			case 3:
				$this->setFechaFinal($value);
				break;
			case 4:
				$this->setActivo($value);
				break;
			case 5:
				$this->setModeloId($value);
				break;
			case 6:
				$this->setTerceroId($value);
				break;
			case 7:
				$this->setUsuarioId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ContratacionContratoPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setFechaCreacion($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setFechaInicial($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFechaFinal($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setActivo($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setModeloId($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setTerceroId($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setUsuarioId($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);

		if ($this->isColumnModified(ContratacionContratoPeer::ID)) $criteria->add(ContratacionContratoPeer::ID, $this->id);
		if ($this->isColumnModified(ContratacionContratoPeer::FECHA_CREACION)) $criteria->add(ContratacionContratoPeer::FECHA_CREACION, $this->fecha_creacion);
		if ($this->isColumnModified(ContratacionContratoPeer::FECHA_INICIAL)) $criteria->add(ContratacionContratoPeer::FECHA_INICIAL, $this->fecha_inicial);
		if ($this->isColumnModified(ContratacionContratoPeer::FECHA_FINAL)) $criteria->add(ContratacionContratoPeer::FECHA_FINAL, $this->fecha_final);
		if ($this->isColumnModified(ContratacionContratoPeer::ACTIVO)) $criteria->add(ContratacionContratoPeer::ACTIVO, $this->activo);
		if ($this->isColumnModified(ContratacionContratoPeer::MODELO_ID)) $criteria->add(ContratacionContratoPeer::MODELO_ID, $this->modelo_id);
		if ($this->isColumnModified(ContratacionContratoPeer::TERCERO_ID)) $criteria->add(ContratacionContratoPeer::TERCERO_ID, $this->tercero_id);
		if ($this->isColumnModified(ContratacionContratoPeer::USUARIO_ID)) $criteria->add(ContratacionContratoPeer::USUARIO_ID, $this->usuario_id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);

		$criteria->add(ContratacionContratoPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setFechaCreacion($this->fecha_creacion);

		$copyObj->setFechaInicial($this->fecha_inicial);

		$copyObj->setFechaFinal($this->fecha_final);

		$copyObj->setActivo($this->activo);

		$copyObj->setModeloId($this->modelo_id);

		$copyObj->setTerceroId($this->tercero_id);

		$copyObj->setUsuarioId($this->usuario_id);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getContratacionAfiliacions() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addContratacionAfiliacion($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getContratacionContratoAVariables() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addContratacionContratoAVariable($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getContratacionOtroSis() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addContratacionOtroSi($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ContratacionContratoPeer();
		}
		return self::$peer;
	}

	
	public function setContratacionModelo(ContratacionModelo $v = null)
	{
		if ($v === null) {
			$this->setModeloId(NULL);
		} else {
			$this->setModeloId($v->getId());
		}

		$this->aContratacionModelo = $v;

						if ($v !== null) {
			$v->addContratacionContrato($this);
		}

		return $this;
	}


	
	public function getContratacionModelo(PropelPDO $con = null)
	{
		if ($this->aContratacionModelo === null && (($this->modelo_id !== "" && $this->modelo_id !== null))) {
			$this->aContratacionModelo = ContratacionModeloPeer::retrieveByPK($this->modelo_id, $con);
			
		}
		return $this->aContratacionModelo;
	}

	
	public function setKernelTercero(KernelTercero $v = null)
	{
		if ($v === null) {
			$this->setTerceroId(NULL);
		} else {
			$this->setTerceroId($v->getId());
		}

		$this->aKernelTercero = $v;

						if ($v !== null) {
			$v->addContratacionContrato($this);
		}

		return $this;
	}


	
	public function getKernelTercero(PropelPDO $con = null)
	{
		if ($this->aKernelTercero === null && ($this->tercero_id !== null)) {
			$this->aKernelTercero = KernelTerceroPeer::retrieveByPK($this->tercero_id, $con);
			
		}
		return $this->aKernelTercero;
	}

	
	public function setKernelUsuario(KernelUsuario $v = null)
	{
		if ($v === null) {
			$this->setUsuarioId(NULL);
		} else {
			$this->setUsuarioId($v->getId());
		}

		$this->aKernelUsuario = $v;

						if ($v !== null) {
			$v->addContratacionContrato($this);
		}

		return $this;
	}


	
	public function getKernelUsuario(PropelPDO $con = null)
	{
		if ($this->aKernelUsuario === null && (($this->usuario_id !== "" && $this->usuario_id !== null))) {
			$this->aKernelUsuario = KernelUsuarioPeer::retrieveByPK($this->usuario_id, $con);
			
		}
		return $this->aKernelUsuario;
	}

	
	public function clearContratacionAfiliacions()
	{
		$this->collContratacionAfiliacions = null; 	}

	
	public function getContratacionAfiliacions($criteria = null, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collContratacionAfiliacions === null) {
			if ($this->isNew()) {
			   $this->collContratacionAfiliacions = array();
			} else {

				$criteria->add(ContratacionAfiliacionPeer::CONTRATO_ID, $this->getId());

				ContratacionAfiliacionPeer::addSelectColumns($criteria);
				$this->collContratacionAfiliacions = ContratacionAfiliacionPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ContratacionAfiliacionPeer::CONTRATO_ID, $this->getId());

				ContratacionAfiliacionPeer::addSelectColumns($criteria);
				if (!isset($this->lastContratacionAfiliacionCriteria) || !$this->lastContratacionAfiliacionCriteria->equals($criteria)) {
					$this->collContratacionAfiliacions = ContratacionAfiliacionPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastContratacionAfiliacionCriteria = $criteria;
		return $this->collContratacionAfiliacions;
	}

	
	public function countContratacionAfiliacions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collContratacionAfiliacions === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ContratacionAfiliacionPeer::CONTRATO_ID, $this->getId());

				$count = ContratacionAfiliacionPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ContratacionAfiliacionPeer::CONTRATO_ID, $this->getId());

				if (!isset($this->lastContratacionAfiliacionCriteria) || !$this->lastContratacionAfiliacionCriteria->equals($criteria)) {
					$count = ContratacionAfiliacionPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collContratacionAfiliacions);
				}
			} else {
				$count = count($this->collContratacionAfiliacions);
			}
		}
		$this->lastContratacionAfiliacionCriteria = $criteria;
		return $count;
	}

	
	public function addContratacionAfiliacion(ContratacionAfiliacion $l)
	{
		if ($this->collContratacionAfiliacions === null) {
			$this->collContratacionAfiliacions = array();
		}
		if (!in_array($l, $this->collContratacionAfiliacions, true)) { 			array_push($this->collContratacionAfiliacions, $l);
			$l->setContratacionContrato($this);
		}
	}

	
	public function clearContratacionContratoAVariables()
	{
		$this->collContratacionContratoAVariables = null; 	}

	
	public function getContratacionContratoAVariables($criteria = null, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collContratacionContratoAVariables === null) {
			if ($this->isNew()) {
			   $this->collContratacionContratoAVariables = array();
			} else {

				$criteria->add(ContratacionContratoAVariablePeer::CONTRATO_ID, $this->getId());

				ContratacionContratoAVariablePeer::addSelectColumns($criteria);
				$this->collContratacionContratoAVariables = ContratacionContratoAVariablePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ContratacionContratoAVariablePeer::CONTRATO_ID, $this->getId());

				ContratacionContratoAVariablePeer::addSelectColumns($criteria);
				if (!isset($this->lastContratacionContratoAVariableCriteria) || !$this->lastContratacionContratoAVariableCriteria->equals($criteria)) {
					$this->collContratacionContratoAVariables = ContratacionContratoAVariablePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastContratacionContratoAVariableCriteria = $criteria;
		return $this->collContratacionContratoAVariables;
	}

	
	public function countContratacionContratoAVariables(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collContratacionContratoAVariables === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ContratacionContratoAVariablePeer::CONTRATO_ID, $this->getId());

				$count = ContratacionContratoAVariablePeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ContratacionContratoAVariablePeer::CONTRATO_ID, $this->getId());

				if (!isset($this->lastContratacionContratoAVariableCriteria) || !$this->lastContratacionContratoAVariableCriteria->equals($criteria)) {
					$count = ContratacionContratoAVariablePeer::doCount($criteria, $con);
				} else {
					$count = count($this->collContratacionContratoAVariables);
				}
			} else {
				$count = count($this->collContratacionContratoAVariables);
			}
		}
		$this->lastContratacionContratoAVariableCriteria = $criteria;
		return $count;
	}

	
	public function addContratacionContratoAVariable(ContratacionContratoAVariable $l)
	{
		if ($this->collContratacionContratoAVariables === null) {
			$this->collContratacionContratoAVariables = array();
		}
		if (!in_array($l, $this->collContratacionContratoAVariables, true)) { 			array_push($this->collContratacionContratoAVariables, $l);
			$l->setContratacionContrato($this);
		}
	}


	
	public function getContratacionContratoAVariablesJoinContratacionVariable($criteria = null, $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collContratacionContratoAVariables === null) {
			if ($this->isNew()) {
				$this->collContratacionContratoAVariables = array();
			} else {

				$criteria->add(ContratacionContratoAVariablePeer::CONTRATO_ID, $this->getId());

				$this->collContratacionContratoAVariables = ContratacionContratoAVariablePeer::doSelectJoinContratacionVariable($criteria, $con);
			}
		} else {
									
			$criteria->add(ContratacionContratoAVariablePeer::CONTRATO_ID, $this->getId());

			if (!isset($this->lastContratacionContratoAVariableCriteria) || !$this->lastContratacionContratoAVariableCriteria->equals($criteria)) {
				$this->collContratacionContratoAVariables = ContratacionContratoAVariablePeer::doSelectJoinContratacionVariable($criteria, $con);
			}
		}
		$this->lastContratacionContratoAVariableCriteria = $criteria;

		return $this->collContratacionContratoAVariables;
	}

	
	public function clearContratacionOtroSis()
	{
		$this->collContratacionOtroSis = null; 	}

	
	public function getContratacionOtroSis($criteria = null, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collContratacionOtroSis === null) {
			if ($this->isNew()) {
			   $this->collContratacionOtroSis = array();
			} else {

				$criteria->add(ContratacionOtroSiPeer::CONTRATO_ID, $this->getId());

				ContratacionOtroSiPeer::addSelectColumns($criteria);
				$this->collContratacionOtroSis = ContratacionOtroSiPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ContratacionOtroSiPeer::CONTRATO_ID, $this->getId());

				ContratacionOtroSiPeer::addSelectColumns($criteria);
				if (!isset($this->lastContratacionOtroSiCriteria) || !$this->lastContratacionOtroSiCriteria->equals($criteria)) {
					$this->collContratacionOtroSis = ContratacionOtroSiPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastContratacionOtroSiCriteria = $criteria;
		return $this->collContratacionOtroSis;
	}

	
	public function countContratacionOtroSis(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		
		if ($criteria === null) {
			$criteria = new Criteria(ContratacionContratoPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collContratacionOtroSis === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ContratacionOtroSiPeer::CONTRATO_ID, $this->getId());

				$count = ContratacionOtroSiPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ContratacionOtroSiPeer::CONTRATO_ID, $this->getId());

				if (!isset($this->lastContratacionOtroSiCriteria) || !$this->lastContratacionOtroSiCriteria->equals($criteria)) {
					$count = ContratacionOtroSiPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collContratacionOtroSis);
				}
			} else {
				$count = count($this->collContratacionOtroSis);
			}
		}
		$this->lastContratacionOtroSiCriteria = $criteria;
		return $count;
	}

	
	public function addContratacionOtroSi(ContratacionOtroSi $l)
	{
		if ($this->collContratacionOtroSis === null) {
			$this->collContratacionOtroSis = array();
		}
		if (!in_array($l, $this->collContratacionOtroSis, true)) { 			array_push($this->collContratacionOtroSis, $l);
			$l->setContratacionContrato($this);
		}
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			foreach($this->collContratacionAfiliacions as $o) {
				$o->clearAllReferences($deep);
			}
			foreach($this->collContratacionContratoAVariables as $o) {
				$o->clearAllReferences($deep);
			}
			foreach($this->collContratacionOtroSis as $o) {
				$o->clearAllReferences($deep);
			}
		} 
		$this->collContratacionAfiliacions = null;
		$this->collContratacionContratoAVariables = null;
		$this->collContratacionOtroSis = null;
	}

} 